import java.io.*;

public class Utils {
		
	public static int Random(int min, int max){
		return (int) Math.round((max - min) * Math.random() - 0.5) + min;
	}
	public static void writeLog(String s){
		File logger=new File("log.txt");
		s+=":\n";
		try {
		if(logger.exists()==false)
		{
			
				logger.createNewFile();
			
		}
		FileOutputStream out = new FileOutputStream(logger, true);//add to the end
		out.write((SystemConfig.getPid()+": "+s).getBytes("US-ASCII"));
		out.close();}
		 catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	
	public static void writeLog(int i){
		File logger=new File("log.txt");
		String s0="RECV and SENT Token:";
		String sn="RECV, ENTERED CRITICAL SECTION: "+i+" and SENT Token";
		try{
		if(logger.exists()==false)
		{
			logger.createNewFile();
		}
		FileOutputStream out = new FileOutputStream(logger, true);//add to the end
		if(i==0)
		out.write(s0.getBytes("US-ASCII"));
		else
			out.write(sn.getBytes("US-ASCII"));
		out.close();}
		 catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
}
